function at = asciitab(tvar, prec, decpoint)
% asciitab  - create custom ASCII representation of 2-D matrix
%
% FORMAT:       ascii = asciitab(tvar [, prec, decpoint])
%
% Input fields:
%
%       tvar        2-D double table data
%       prec        precision argument (for any2ascii)
%       decpoint    locale selectable decimal point character
%
% Output fields:
%
%       ascii       ascii version of table data
%
% See also any2ascii

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~isa(tvar, 'double') || ...
   ndims(tvar) > 2
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid or missing tvar argument.' ...
    );
end
if nargin < 2 || ...
   ~isa(prec, 'double')
    prec = 8;
end
if nargin < 3 || ...
   ~ischar(decpoint)
    decpoint = '.';
end

% conversion
at = any2ascii(tvar, prec, 1);

% formatting
at(at == ',' | at == ';' | at == char(9)) = [];
at = strrep(at, '...', '');

% decimal point
at = strrep(at, '.', decpoint);

% get first and last character right
at(end) = char(10);
at = at(2:end);
